﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using MediaScraper.Adapters.Plex;
using MediaScraper.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Win32;

namespace MediaScraper.Agents.OSDB.Tests
{
    //http://trac.opensubtitles.org/projects/opensubtitles/wiki/XMLRPC#SearchSubtitles
    [TestClass]
    public class MovieTests
    {
        private const string ImdbName = "Now You See Me (2013)";
        private const string ReleaseName = "Now.You.See.Me.2013.BDRip.X264-SPARKS";
        private const string Path = @"C:\Temp\";
        private readonly List<string> _languages = new List<string>() { "eng" }; //important: three letter code ger por etc
        
        [TestMethod]
        public void TestDownloadSubtitleByQueryReleaseName()
        {
            OSDBAgent mediaAgent = new OSDBAgent();
            string releaseName = "Breaking.Bad.S05E08.Gliding.Over.All.German.AC3D.D L.720p.WEB-DL.H264-PRETAiL";
            var file = mediaAgent.GetInfoByFileName(releaseName, new List<CultureInfo>{CultureInfo.CreateSpecificCulture("en-US")});
            Assert.IsNotNull(file);
            
            PlexAdapter plexAdapter = new PlexAdapter();
            file = plexAdapter.ProcessVideoInfo(file);
            var tvShows = plexAdapter.GetMoviesRootFolder();
            var movies = plexAdapter.GetSeriesRootFolders();
        }

        
        //[TestMethod]
        //public void TestDownloadSubtitleByFileAndMove()
        //{
        //    MediaAgent mediaAgent = new MediaAgent();
        //    var file = Path + ReleaseName + ".mkv";

        //    if (!File.Exists(file))
        //    {
        //        throw new Exception(string.Format("Could not find the file '{0}'", file));
        //    }

        //    var mediaInfo = mediaAgent.GetFileInfo(file, _languages);
        //    if (!string.IsNullOrWhiteSpace(mediaInfo.Name))
        //    {
        //        FileManager fm = new FileManager();
        //        fm.RenameFile(file, mediaInfo.Name);    
        //        mediaAgent.DownloadSubtitle(mediaInfo.SubtitleUrl,mediaInfo.Name,"eng");
        //    }

        //}

        //[TestMethod]
        //public void ReadRegistry()
        //{
        //    string installPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\MediaScraper", "InstallPath", null);
        //    Debug.WriteLine(installPath);
        //    Assert.IsNotNull(installPath);
        //}



      

    }
}
